//
// Created by bxw57 on 2024/6/11.
//

#include <iostream>
#include "SqList.h"
using namespace std;

void SqList::push(int val) {
    arr[top++] = val;
}

int SqList::pop() {
    return arr[--top];
}

int SqList::pop(int index) {
    if (0 <= index && index < top) {
        int tmp = arr[index];
        for (int i = index+1; i<top; i++)
            arr[i-1] = arr[i];
        top--;
        return tmp;
    }
    else
        return 9999999;
}

SqList SqList::operator+(SqList &list) {
    SqList tmp(cap);
    while (top != 0)
        tmp.push(this->pop(0));
    while (list.top != 0)
        tmp.push(list.pop(0));
    return tmp;
}

void SqList::show() {
    for (int i = 0; i < top; i++)
        cout << arr[i] << " ";
    cout << endl;
}

SqList::SqList(SqList const &list) {
    cap = list.cap;
    top = list.top;
    arr = new int[cap];
    for (int i = 0; i < top; i++)
        arr[i] = list.arr[i];
}

